﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;

internal class FlashTemplateWriterUtility
{
    private readonly string _outputFile;
    private readonly Dictionary<string, string> _tagsToReplace;
    private readonly string _templateFile;
    [CompilerGenerated]
    private static Func<string, KeyValuePair<string, string>, string> <>f__am$cache3;

    public FlashTemplateWriterUtility(string templateFile, string outputFile, Dictionary<string, string> tagsToReplace)
    {
        this._outputFile = outputFile;
        this._tagsToReplace = tagsToReplace;
        this._templateFile = templateFile;
    }

    private static Dictionary<string, string> GetTagsToReplaceForHTML(FlashPostProcessSettings settings, FlashFileHelper fileHelper)
    {
        int num = settings.Height / 2;
        Dictionary<string, string> dictionary = new Dictionary<string, string>();
        dictionary.Add("hdimy", num.ToString());
        dictionary.Add("dimx", settings.Width.ToString());
        dictionary.Add("dimy", settings.Height.ToString());
        dictionary.Add("swfname", fileHelper.ProjectName() + ".swf");
        dictionary.Add("flashplayer_version", settings.GetTargetPlayerForSubtarget());
        return dictionary;
    }

    public static void WriteGendarmeXMLTemplate(FlashPostProcessSettings settings, FlashFileHelper fileHelper, GendarmeXMLTemplateTags gendarmeXMLTemplateTags, string output)
    {
        new FlashTemplateWriterUtility(fileHelper.PathForFileInGendarme("rules_template.xml"), output, gendarmeXMLTemplateTags.ToTagsDictionary()).WriteTemplate();
    }

    public static void WriteHTMLTemplate(FlashPostProcessSettings settings, FlashFileHelper fileHelper)
    {
        new FlashTemplateWriterUtility(fileHelper.PathForFileInBuildTools("index.html"), fileHelper.PathForHtmlInInstallPath(), GetTagsToReplaceForHTML(settings, fileHelper)).WriteTemplate();
    }

    public void WriteTemplate()
    {
        string str = File.ReadAllText(this._templateFile);
        if (<>f__am$cache3 == null)
        {
            <>f__am$cache3 = (current, kvp) => current.Replace("[%" + kvp.Key + "%]", kvp.Value);
        }
        string contents = Enumerable.Aggregate<KeyValuePair<string, string>, string>(this._tagsToReplace, str, <>f__am$cache3);
        File.WriteAllText(this._outputFile, contents);
    }
}

